import numpy as np
import cv2
# 暴力特征匹配

img1 = cv2.imread("C:\\Users\\86191\\Pictures\\Saved Pictures\\Camera Roll\\op1.jpg")
img2 = cv2.imread("C:\\Users\\86191\\Pictures\\Saved Pictures\\Camera Roll\\op3.jpg")
# 灰度化
g1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
g2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
# 创建sift对象
sift = cv2.SIFT_create()
# 计算描述子
kp1,des1= sift.detectAndCompute(g1,None)
kp2,des2= sift.detectAndCompute(g2,None)
# 创建匹配器
bf = cv2.BFMatcher(cv2.NORM_L1)
match = bf.match(des1,des2)
# 绘制匹配
img3 = cv2.drawMatches(img1,kp1,img2,kp2,match,None)
cv2.imshow("img3",img3)
cv2.waitKey(0)